class Solution(object):
    def maxValue(self, n, x):
        x = str(x)
        m = len(n)
        if n[0] == '-':
            index = 1
            while index < m and n[index] <= x:
                index += 1
            return n[:index] + x + n[index:]
        else:
            index = 0
            while index < m and n[index] >= x:
                index += 1
            return n[:index] + x + n[index:]



